/* Copyright (C) 2008 Lorenzo Braghetto
 * 
 * This file is part of BatteryDiff Widget.
 * 
 *   BatteryDiff Widget is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *   
 *  BatteryDiff Widget is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
*/

package com.mono.diffwidget;

import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class About extends Activity implements OnClickListener {

	public static final String PREFS_NAME = "DiffWidgetPrefs";
	public static final String PREFS_NAME2 = "TimePref";

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.about);

		SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
		SharedPreferences settings2 = getSharedPreferences(PREFS_NAME2, 0);
		
		float temperatureI = settings2.getFloat("temperature", 0);
		TextView temperature = (TextView) findViewById(R.id.temperature);
		temperature.setText(temperatureI+"°c");

		float tempo = settings.getFloat("tempo", 0.0f);
		float battdiff = settings.getFloat("battdiff", 0.0f);
		boolean incarica = settings2.getBoolean("incarica", false);

		if (incarica == false) {
			TextView info = (TextView) this.findViewById(R.id.info);
			info.setText("You have used " + (int) battdiff + "% of battery in "
					+ (int) tempo + " minutes");
		} else {
			TextView info = (TextView) this.findViewById(R.id.info);
			info.setText("You have charged " + ((int) battdiff * -1)
					+ "% of battery in " + (int) tempo + " minutes");
		}

		View aboutButton = findViewById(R.id.About);
		aboutButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {

				Dialog dialog = new Dialog(About.this);
				dialog.setContentView(R.layout.aboutdialog);
				dialog.setTitle("About");
				dialog.show();
			}
		});
	}

	@Override
	public void onClick(DialogInterface arg0, int arg1) {
		// TODO Auto-generated method stub

	}

}